package uno.component;

import java.awt.Dimension;
import java.awt.Graphics;
import java.util.LinkedList;

import javax.swing.JPanel;


/**
 * 
 * Rappresenta la lista di carte che sono state giocate
 * */
public class PlayedCardsList extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5982487858941334096L;
	
	/**
	 * */
	private LinkedList<Card> cardsList;
	
	
	/**
	 * 
	 * */
	public PlayedCardsList(Card firstCard) {
		
		this.cardsList = new LinkedList<Card>();
		this.cardsList.add(firstCard);
		
	}
	
	/**
	 * 
	 * */
	public void addCard(Card card) {
		
		cardsList.add(card);
		update(getGraphics());
		
	}
	
	/**
	 * 
	 * */
	public Card getLastPlayedCard() {
		
		return cardsList.getLast();
	}
	
	/* (non-Javadoc)
	 * @see javax.swing.JComponent#getPreferredSize()
	 */
	@Override
	public Dimension getPreferredSize() {
		//return new Dimension(CardFactory.getCardHeight(), CardFactory.getCardWidth() + DECK_SIZE);
		return new Dimension(CardFactory.getCardWidth(), CardFactory.getCardHeight());
	}
	
	@Override
	public void paint(Graphics g) {		
		super.paint(g);
		//disegna l'ultima carta giocata
		g.drawImage(getLastPlayedCard().getValue().getCardImage(), 0, 0 , CardFactory.getCardWidth(), CardFactory.getCardHeight(), this);
		validate();			
	}
}
